﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Model
{
    public class LocationRepository
    {
        private JzSportDbContext _dbContext;

        public LocationRepository(JzSportDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public void Save(Location location)
        {
            _dbContext.Set<Location>().Add(location);
        }

        public void Update(Guid id, Location location)
        {
            _dbContext.Entry<Location>(location).State = System.Data.EntityState.Modified;
        }

        public Location GetLatest(int accountId)
        {
            return _dbContext.Set<Location>().Where(p => p.AccountId == accountId && p.IsLatest == true).SingleOrDefault();
        }
    }
}
